<template>
  <nav class="navbar navbar-dark bg-primary justify-center-between mb-4 px-4">
    <router-link class="navbar-brand" :to="{ name: 'home' }">言</router-link>
    <ul v-if="!props.user.isLogin">
      <li class="list-inline-item">
        <router-link :to="{ name: 'login' }" class="btn btn-outline-light my-2">登陆</router-link>
      </li>
      <li class="list-inline-item">
        <router-link :to="{ name: 'signup' }" class="btn btn-outline-light my-2">注册</router-link>
      </li>
    </ul>
    <ul v-else>
      <li class="list-inline-item">
        <Dropdown :title="`你好${props.user.nickName}!!`">
          <DropdownItem>
            <!-- 插槽 -->
            <template #default>
              <router-link class="dropdown-item" :to="{ name: 'create' }">新建文章</router-link>
            </template>
          </DropdownItem>
          <DropdownItem>
            <template #default>
              <router-link class="dropdown-item" :to="{ name: 'column', params: { id: props.user.column } }">我的专栏
              </router-link>
            </template>
          </DropdownItem>
          <!-- <DropdownItem>
            <template #default>
              <a class="dropdown-item" href="#">编辑资料</a>
            </template>
          </DropdownItem> -->

          <DropdownItem>
            <template #default>
              <router-link class="dropdown-item" :to="{ name: 'login' }" @click="outLogin">退出登陆</router-link>
            </template>
          </DropdownItem>
        </Dropdown>
      </li>
    </ul>
  </nav>
</template>

<script setup lang="ts">
import Dropdown from './Dropdown.vue';
import DropdownItem from './DropdownItem.vue';
import { UserInfo } from '../store/store';
import { useStore } from 'vuex';
export interface Props {
  user: UserInfo
}
const stort = useStore()
let props = defineProps<Props>()
const outLogin = () => {
  localStorage.removeItem('toKen')
  stort.commit('OUTLOGIN')
}
</script>

<style>
</style>